package cn.abyss.admin.exception;

import cn.abyss.admin.enums.BaseAdminWebExceptionEnum;
import cn.abyss.admin.enums.BaseAdminWebExceptionLevelEnum;

/**
 * Description:
 *
 * @author zhangsj
 * @date Created on 2020/12/15
 */
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = -5664201357450861646L;
    private final String code;
    private final BaseAdminWebExceptionLevelEnum level;

    public BaseException(String message, Throwable cause) {
        super(message, cause);
        this.code = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getCode();
        this.level = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getLevel();
    }

    public BaseException(Throwable cause) {
        super(cause);
        this.code = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getCode();
        this.level = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getLevel();
    }

    protected BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getCode();
        this.level = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getLevel();
    }

    public BaseException(String pcode, String mcode, String bcode, String message) {
        this(pcode, mcode, bcode, message, BaseAdminWebExceptionLevelEnum.INTERNAL_EXCEPTION);
    }

    public BaseException(String pcode, String mcode, String bcode, String message, BaseAdminWebExceptionLevelEnum level) {
        super(message);
        this.code = pcode + mcode + bcode;
        this.level = level;
    }

    public BaseException(String pcode, String mcode, String bcode, String message, Throwable cause) {
        this(pcode, mcode, bcode, message, BaseAdminWebExceptionLevelEnum.INTERNAL_EXCEPTION, cause);
    }

    public BaseException(String pcode, String mcode, String bcode, String message, BaseAdminWebExceptionLevelEnum level, Throwable cause) {
        super(message, cause);
        this.code = pcode + mcode + bcode;
        this.level = level;
    }

    public BaseException(String code, String message) {
        this(code, message, BaseAdminWebExceptionLevelEnum.INTERNAL_EXCEPTION);
    }

    public BaseException(String code, String message, BaseAdminWebExceptionLevelEnum level) {
        super(message);
        this.code = code;
        this.level = level;
    }

    public BaseException(String message) {
        super(message);
        this.code = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getCode();
        this.level = BaseAdminWebExceptionEnum.USER_DEFINED_ERROR.getLevel();
    }

    public BaseException(BaseAdminWebExceptionEnum e) {
        super(e.getMessage());
        this.code = e.getCode();
        this.level = e.getLevel();
    }

    public String getCode() {
        return this.code;
    }

    public BaseAdminWebExceptionLevelEnum getLevel() {
        return this.level;
    }
}
